home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2002 November / SGI IRIX Base Documentation 2002 November.iso / usr / share / catman / p_man / cat3 / librw / RWCRExpr.z / RWCRExpr
Encoding:
Text File  |  2002-10-03  |  14.3 KB  |  265 lines

  1.  
  2.  
  3.  
  4. RRRRWWWWCCCCRRRREEEExxxxpppprrrr((((3333CCCC++++++++))))                                                  RRRRWWWWCCCCRRRREEEExxxxpppprrrr((((3333CCCC++++++++))))
  5.  
  6.  
  7.  
  8. NNNNaaaammmmeeee
  9.      RWCRExpr - Rogue Wave library class
  10.  
  11. SSSSyyyynnnnooooppppssssiiiissss
  12.               #include <rw/re.h>
  13.  
  14.  
  15.  
  16.               RWCRExpr re(".*\.doc");  // Matches filename with suffix ".doc"
  17.  
  18.  
  19.  
  20.  
  21. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn
  22.      Class RRRRWWWWCCCCRRRREEEExxxxpppprrrr represents an eeeexxxxtttteeeennnnddddeeeedddd regular expression such as those
  23.      found in lllleeeexxxx and aaaawwwwkkkk.  The constructor "compiles" the expression into a
  24.      form that can be used more efficiently.  The results can then be used for
  25.      string searches using class RRRRWWWWCCCCSSSSttttrrrriiiinnnngggg.   Regular expressions can be of
  26.      arbitrary size, limited by memory. The extended regular expression
  27.      features found here are a subset of those found in the POSIX.2 standard
  28.      (AAAANNNNSSSSIIII////IIIIEEEEEEEEEEEE SSSSttttdddd 1111000000003333....2222,,,, IIIISSSSOOOO////IIIIEEEECCCC 9999999944445555----2222)))).... NNNNooootttteeee:::: RRRRWWWWCCCCRRRREEEExxxxpppprrrr iiiissss aaaavvvvaaaaiiiillllaaaabbbblllleeee oooonnnnllllyyyy
  29.      iiiiffff yyyyoooouuuurrrr ccccoooommmmppppiiiilllleeeerrrr ssssuuuuppppppppoooorrrrttttssss eeeexxxxcccceeeeppppttttiiiioooonnnn hhhhaaaannnnddddlllliiiinnnngggg aaaannnndddd tttthhhheeee CCCC++++++++ SSSSttttaaaannnnddddaaaarrrrdddd
  30.      LLLLiiiibbbbrrrraaaarrrryyyy....  The regular expression (RE) is constructed as follows:  The
  31.      following rules determine one-character REs that match a ssssiiiinnnngggglllleeee
  32.      character:  Any character that is not a special character (to be defined)
  33.      matches itself.
  34.           A backslash (\\\\ffffRRRR)))) ffffoooolllllllloooowwwweeeedddd bbbbyyyy aaaannnnyyyy ssssppppeeeecccciiiiaaaallll cccchhhhaaaarrrraaaacccctttteeeerrrr mmmmaaaattttcccchhhheeeessss tttthhhheeee
  35.           lllliiiitttteeeerrrraaaallll cccchhhhaaaarrrraaaacccctttteeeerrrr iiiittttsssseeeellllffff;;;; tttthhhhaaaatttt iiiissss,,,,  tttthhhhiiiissss """"eeeessssccccaaaappppeeeessss"""" tttthhhheeee ssssppppeeeecccciiiiaaaallll
  36.           cccchhhhaaaarrrraaaacccctttteeeerrrr....
  37.  
  38.           TTTThhhheeee """"ssssppppeeeecccciiiiaaaallll cccchhhhaaaarrrraaaacccctttteeeerrrrssss"""" aaaarrrreeee::::  ++++ **** ????  .... [[[[  ]]]] ^^^^ $$$$ (((( )))) {{{{ }}}} |||| \\\\ffffPPPP
  39.  
  40.           TTTThhhheeee ppppeeeerrrriiiioooodddd ((((....) matches any character.  EEEE....gggg...., "....uuuummmmppppttttyyyy" matches either
  41.           "HHHHuuuummmmppppttttyyyy" or "DDDDuuuummmmppppttttyyyy...."
  42.  
  43.           A set of characters enclosed in brackets ([[[[ ]]]]) is a one-character RE
  44.           that matches any of the characters in that set.  EEEE....gggg...., "[[[[aaaakkkkmmmm]]]]"
  45.           matches either an "aaaa", "kkkk", or "mmmm".  A range of characters can be
  46.           indicated with a dash.  EEEE....gggg...., "[[[[aaaa----zzzz]]]]" matches any lower-case letter.
  47.           However, if the first character of the set is the caret (^^^^), then
  48.           the RE matches any character eeeexxxxcccceeeepppptttt those in the set.  It does nnnnooootttt
  49.           match the empty string.  Example: [[[[^^^^aaaakkkkmmmm]]]] matches any character
  50.           eeeexxxxcccceeeepppptttt  "aaaa", "kkkk", or "mmmm".  The caret loses its special meaning if it
  51.           is not the first character of the set.  The following rules can be
  52.           used to build a multicharacter RE:
  53.  
  54.           Parentheses ((((( ))))) group parts of regular expressions together into
  55.           subexpressions that can be treated as a single unit.  For example,
  56.           ((((hhhhaaaa))))++++ matches one or more "ha"'s.
  57.  
  58.           A one-character RE followed by an asterisk (****) matches zzzzeeeerrrroooo or more
  59.           occurrences of the RE.  Hence, [[[[aaaa----zzzz]]]]**** matches zero or more lower-
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. RRRRWWWWCCCCRRRREEEExxxxpppprrrr((((3333CCCC++++++++))))                                                  RRRRWWWWCCCCRRRREEEExxxxpppprrrr((((3333CCCC++++++++))))
  71.  
  72.  
  73.  
  74.           case characters.
  75.  
  76.           A one-character RE followed by a plus (++++) matches oooonnnneeee or more
  77.           occurrences of the RE.  Hence, [[[[aaaa----zzzz]]]]++++ matches one or more lower-case
  78.           characters.
  79.  
  80.           A question mark (????) is an optional element.  The preceeding RE can
  81.           occur zero or once in the string -- no more.  EEEE....gggg.... xxxxyyyy????zzzz matches
  82.           either xxxxyyyyzzzz or xxxxzzzz.
  83.  
  84.           The concatenation of REs is a RE that matches the corresponding
  85.           concatenation of strings.  EEEE....gggg...., [A-Z][a-z]* matches any capitalized
  86.           word.
  87.  
  88.           The OR character  ( |||| ) allows a choice between two regular
  89.           expressions.  For example, jjjjeeeellllllll((((yyyy||||iiiieeeessss)))) matches either "jelly" or
  90.           "jellies".
  91.  
  92.           Braces ({{{{ }}}}) are reserved for future use.
  93.  
  94.           All or part of the regular expression can be "anchored" to either
  95.           the beginning or end of the string being searched:
  96.  
  97.           If the caret (^^^^) is at the beginning of the (sub)expression, then
  98.           the matched string must be at the beginning of the string being
  99.           searched.
  100.  
  101.           If the dollar sign ($$$$) is at the end of the (sub)expression, then
  102.           the matched string must be at the end of the string being searched.
  103.  
  104.  
  105. PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee
  106.      None
  107.  
  108. EEEExxxxaaaammmmpppplllleeee
  109.               #include <rw/re.h>
  110.           #include <rw/cstring.h>
  111.           #include <rw/rstream.h>
  112.           main(){
  113.             RWCString aString("Hark! Hark! the lark");
  114.             // A regular expression matching any lowercase word or end of a
  115.             //word starting with "l":
  116.                RWCRExpr re("l[a-z]*");
  117.             cout << aString(re) << endl;  // Prints "lark"
  118.           }
  119.  
  120. PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss
  121.               RRRRWWWWCCCCRRRREEEExxxxpppprrrr(const char* pat);
  122.           RRRRWWWWCCCCRRRREEEExxxxpppprrrr(const RWCString& pat);
  123.  
  124.  
  125.      Construct a regular expression from the pattern given by ppppaaaatttt.  The status
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. RRRRWWWWCCCCRRRREEEExxxxpppprrrr((((3333CCCC++++++++))))                                                  RRRRWWWWCCCCRRRREEEExxxxpppprrrr((((3333CCCC++++++++))))
  137.  
  138.  
  139.  
  140.      of the results can be found by using member function ssssttttaaaattttuuuussss(((()))).
  141.  
  142.               RRRRWWWWCCCCRRRREEEExxxxpppprrrr(const RWCRExpr& r);
  143.  
  144.  
  145.      Copy constructor.  Uses value semantics -- self will be a copy of rrrr.
  146.  
  147.               RRRRWWWWCCCCRRRREEEExxxxpppprrrr();
  148.  
  149.  
  150.      Default constructor.  You must assign a pattern to the regular expression
  151.      before you use it.
  152.  
  153. PPPPuuuubbbblllliiiicccc DDDDeeeessssttttrrrruuuuccccttttoooorrrr
  154.               ~RRRRWWWWCCCCRRRREEEExxxxpppprrrr();
  155.  
  156.  
  157.      Destructor.  Releases any allocated memory.
  158.  
  159. AAAAssssssssiiiiggggnnnnmmmmeeeennnntttt OOOOppppeeeerrrraaaattttoooorrrrssss
  160.               RWCRExpr&
  161.           ooooppppeeeerrrraaaattttoooorrrr====(const RWCRExpr& r);
  162.  
  163.  
  164.      Recompiles self to pattern found in rrrr.
  165.  
  166.               RWCRExpr&
  167.           ooooppppeeeerrrraaaattttoooorrrr====(const char* pat);
  168.           RWCRExpr&
  169.           ooooppppeeeerrrraaaattttoooorrrr====(const RWCString& pat);
  170.  
  171.  
  172.      Recompiles self to the pattern given by ppppaaaatttt.  The status of the results
  173.      can be found by using member function ssssttttaaaattttuuuussss(((()))).
  174.  
  175. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss
  176.               size_t
  177.           iiiinnnnddddeeeexxxx(const RWCString& str, size_t* len = NULL,
  178.                 size_t start=0) const;
  179.  
  180.  
  181.      Returns the index of the first instance in the string ssssttttrrrr that matches
  182.      the regular expression compiled in self, or RRRRWWWW____NNNNPPPPOOOOSSSS if there is no such
  183.      match.  The search starts at index ssssttttaaaarrrrtttt.  The length of the matching
  184.      pattern is returned in the variable pointed to by lllleeeennnn. If an invalid
  185.      regular expression is used for the search, an exception of type
  186.      RRRRWWWWIIIInnnntttteeeerrrrnnnnaaaallllEEEErrrrrrrr will be thrown.  Note that this member function is
  187.      relatively clumsy to use -- class RRRRWWWWCCCCSSSSttttrrrriiiinnnngggg offers a better interface to
  188.      regular expression searches.
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. RRRRWWWWCCCCRRRREEEExxxxpppprrrr((((3333CCCC++++++++))))                                                  RRRRWWWWCCCCRRRREEEExxxxpppprrrr((((3333CCCC++++++++))))
  203.  
  204.  
  205.  
  206.               statusType
  207.           ssssttttaaaattttuuuussss() const;
  208.  
  209.  
  210.      Returns the status of the regular expression:
  211.  
  212.  
  213.      ssssttttaaaattttuuuussssTTTTyyyyppppeeee MMMMeeeeaaaannnniiiinnnngggg
  214.  
  215.  
  216.      RRRRWWWWCCCCRRRREEEExxxxpppprrrr::::::::OOOOKKKK No errors
  217.  
  218.  
  219.      RRRRWWWWCCCCRRRREEEExxxxpppprrrr::::::::NNNNOOOOTTTT____SSSSUUUUPPPPPPPPOOOORRRRTTTTEEEEDDDD POSIX.2 feature not yet supported.
  220.  
  221.  
  222.      RRRRWWWWCCCCRRRREEEExxxxpppprrrr::::::::NNNNOOOO____MMMMAAAATTTTCCCCHHHH Tried to find a match but failed
  223.  
  224.  
  225.      RRRRWWWWCCCCRRRREEEExxxxpppprrrr::::::::BBBBAAAADDDD____PPPPAAAATTTTTTTTEEEERRRRNNNN Pattern was illegal
  226.  
  227.  
  228.      RRRRWWWWCCCCRRRREEEExxxxpppprrrr::::::::BBBBAAAADDDD____CCCCOOOOLLLLLLLLAAAATTTTIIIINNNNGGGG____EEEELLLLEEEEMMMMEEEENNNNTTTT Invalid collating element referenced
  229.  
  230.  
  231.      RRRRWWWWCCCCRRRREEEExxxxpppprrrr::::::::BBBBAAAADDDD____CCCCHHHHAAAARRRR____CCCCLLLLAAAASSSSSSSS____TTTTYYYYPPPPEEEE Invalid character class type referenced
  232.  
  233.  
  234.      RRRRWWWWCCCCRRRREEEExxxxpppprrrr::::::::TTTTRRRRAAAAIIIILLLLIIIINNNNGGGG____BBBBAAAACCCCKKKKSSSSLLLLAAAASSSSHHHH Trailing  in pattern
  235.  
  236.  
  237.      RRRRWWWWCCCCRRRREEEExxxxpppprrrr::::::::UUUUNNNNMMMMAAAATTTTCCCCHHHHEEEEDDDD____BBBBRRRRAAAACCCCKKKKEEEETTTT [] imbalance
  238.  
  239.  
  240.      RRRRWWWWCCCCRRRREEEExxxxpppprrrr::::::::UUUUNNNNMMMMAAAATTTTCCCCHHHHEEEEDDDD____PPPPAAAARRRREEEENNNNTTTTHHHHEEEESSSSIIIISSSS () imbalance
  241.  
  242.  
  243.      RRRRWWWWCCCCRRRREEEExxxxpppprrrr::::::::UUUUNNNNMMMMAAAATTTTCCCCHHHHEEEEDDDD____BBBBRRRRAAAACCCCEEEE {} imbalance
  244.  
  245.  
  246.      RRRRWWWWCCCCRRRREEEExxxxpppprrrr::::::::BBBBAAAADDDD____BBBBRRRRAAAACCCCEEEE Content of {} invalid.
  247.  
  248.  
  249.      RRRRWWWWCCCCRRRREEEExxxxpppprrrr::::::::BBBBAAAADDDD____CCCCHHHHAAAARRRR____RRRRAAAANNNNGGGGEEEE Invalid endpoint in [a-z] expression
  250.  
  251.  
  252.      RRRRWWWWCCCCRRRREEEExxxxpppprrrr::::::::OOOOUUUUTTTT____OOOOFFFF____MMMMEEEEMMMMOOOORRRRYYYY Out of memory
  253.  
  254.  
  255.      RRRRWWWWCCCCRRRREEEExxxxpppprrrr::::::::BBBBAAAADDDD____RRRREEEEPPPPEEEEAAAATTTT ?,* or + not preceded by valid regular expression
  256.  
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.